package com.foreveross.mofang.datapersistence.core;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * @author fb
 */
@MappedSuperclass
public abstract class RDBMSBaseEntity extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	public String[] businessKeys() {
		return null;
	}

	@NotNull(message = "rowKey不能为空!")
	@Column(name = "ROWKEY")
	private String rowKey;
	
	@NotNull(message = "内容不能为空!")
	@Lob
	@Column(name = "CONTENT")
	private String content;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATE_DATE")
	private Date createDate;
	
	@NotNull(message = "渠道编码不能为空!")
	@Column(name = "CHANNEL_SN")
	private String channelSn;

	public RDBMSBaseEntity() {
		super();
	}
	
	public RDBMSBaseEntity(String rowKey, String content, Date createDate) {
		super();
		this.rowKey = rowKey;
		this.content = content;
		this.createDate = createDate;
	}

	public String getRowKey() {
		return rowKey;
	}

	public void setRowKey(String rowKey) {
		this.rowKey = rowKey;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getRowKey())
				.append(getId()).toHashCode();
	}

	@Override
	public boolean equals(Object other) {
		if (!(other instanceof RDBMSBaseEntity)) {
			return false;
		}
		RDBMSBaseEntity that = (RDBMSBaseEntity) other;
		return new EqualsBuilder()
				.append(this.getRowKey(), that.getRowKey())
				.append(this.getId(), that.getId()).isEquals();
	}
	
	
}
